# -*- coding: utf-8 -*-
import time
import json
import messAround.util.database as dbhelp
from collections import OrderedDict

fetched_at = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# 日期
day = time.strftime("%Y%m%d", time.localtime())
# 时段
hour = time.strftime("%H", time.localtime())

agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 ' \
        'Safari/537.36 '

default_headers = {
    'User-Agent': agent
}


#

def make_json(res, sort=1):
    if sort == 1:
        result = json.loads(res, object_pairs_hook=OrderedDict)
    else:
        result = json.loads(res)

    return result


# 组装数据
def make_data(data, item):
    return dict({
        'no': item['no'],
        'day': int(day),
        'hour': int(hour),
        'fetched_at': fetched_at,
    }, **data)


# 组装数据并写入
def make_write_data(data, item, model):
    result = dict({
        'no': item['no'],
        'day': int(day),
        'hour': int(hour),
        'fetched_at': fetched_at,
    }, **data)
    db = dbhelp.MysqlHelpers(model)
    db.write(result)
    return result


def test():
    print(1)
